from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib

def _format_add(s):
    name, addr = parseaddr(s)
    return formataddr((Header(name, 'utf-8').encode(), addr))

fromaddr = "rain_vigour@163.com"
pwd = "caijinta0"
to_addr = "645597501@qq.com"
#163邮箱服务器地址
smtp_server = "smtp.163.com"
#设置发送的内容
msg = MIMEText('多一点努力，就能多一份博弈机会', 'plain', 'utf-8')
msg['From'] = _format_add("人生格言<%s>" % fromaddr)
print(msg['From'])
msg['To'] = _format_add("喵喵<%s>" % to_addr)
print(msg['To'])
msg['Subject'] = Header("人生的状态应该积极的！", 'utf-8').encode()
print(msg['Subject'])
#发送邮件
server = smtplib.SMTP(smtp_server, 25)
server.login(fromaddr, pwd)
server.sendmail(fromaddr, [to_addr], msg.as_string())
server.quit()
